<?php
namespace App\Http\Controllers\Mp;
use App\Http\Resources\Mp\BookOrderResource;
use App\Models\BookOrder;
use Illuminate\Http\Request;

/**
 * Class BillController
 * @package App\Http\Controllers\Mp
 * @author zjw
 */
class BillController extends BaseController{
    public function index(Request $request) {
        $month = $request->get('month');
        if(!$month){
            $month = now()->format("Y-m");
        }
        $query = BookOrder::whereHas('rule',function($query) use ($month){
            $query->month($month);
        })->belongToUser()->isCalculated()->isNotCanceled();
        $totalMoney = $query->sum('pay_price');
        $list = $query->orderBy('created_at','desc')->with('rule')->get();
        return [
            'total'=> $totalMoney,
            'data'=> BookOrderResource::collection($list),
            'month'=> $month
        ];
    }
}
